package com.isoft.mapper;

import com.isoft.entity.BaseApueEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface BaseApueMapper {

    // 方案1：让数据库自动生成ID（推荐方案）
    @Insert("INSERT INTO MSG_META(" +
            "SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) " +
            "VALUES(" +
            "#{meta.sender,jdbcType=VARCHAR}, " +
            "#{meta.receiver,jdbcType=VARCHAR}, " +
            "#{meta.sequenceNumber,jdbcType=NUMERIC}, " +
            "TO_TIMESTAMP(#{meta.dateTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), " +
            "#{meta.type,jdbcType=VARCHAR}, " +
            "#{meta.subType,jdbcType=VARCHAR})")
    @Options(useGeneratedKeys = true, keyProperty = "meta.msgId", keyColumn = "MSG_ID")
    void insertMeta(BaseApueEntity entity);

    // 方案2：如果需要显式控制ID（使用前需确保表已设置IDENTITY_INSERT ON）
    /*
    @Insert({
        "<script>",
        "SET IDENTITY_INSERT MSG_META ON",
        "INSERT INTO MSG_META(MSG_ID, SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) ",
        "VALUES(#{meta.msgId,jdbcType=NUMERIC}, ",
        "#{meta.sender,jdbcType=VARCHAR}, ",
        "#{meta.receiver,jdbcType=VARCHAR}, ",
        "#{meta.sequenceNumber,jdbcType=NUMERIC}, ",
        "TO_TIMESTAMP(#{meta.dateTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), ",
        "#{meta.type,jdbcType=VARCHAR}, ",
        "#{meta.subType,jdbcType=VARCHAR})",
        "SET IDENTITY_INSERT MSG_META OFF",
        "</script>"
    })
    void insertMetaWithId(BaseApueEntity entity);
    */

    @Insert("INSERT INTO AIRPORT(" +
            "AIRPORT_CODE, IATA_CODE, AIRPORT_TERMINAL, CHINESE_NAME, " +
            "ENGLISH_NAME, IS_OPEN, SHORT_NAME) " +
            "VALUES(" +
            "#{apot.airportCode,jdbcType=VARCHAR}, " +
            "#{apot.iataCode,jdbcType=VARCHAR}, " +
            "#{apot.airportTerminal,jdbcType=VARCHAR}, " +
            "#{apot.chineseName,jdbcType=VARCHAR}, " +
            "#{apot.englishName,jdbcType=VARCHAR}, " +
            "#{apot.isOpen,jdbcType=CHAR}, " +
            "#{apot.shortName,jdbcType=VARCHAR})")
    int insertAirport(BaseApueEntity entity);
}